#!/bin/sh
#
# This systemtest tests the vmware plugin functionality
# of the Susan FD by using the supplied module
#   SusanFdPluginVMware.py
#
TestName="$(basename "$(pwd)")"
export TestName

JobName=backup-susan-fd
#shellcheck source=../environment.in
. ./environment

export PATH="$(pwd)/bin:$PATH"

JobName=backup-susan-fd
#shellcheck source=../scripts/functions
. "${rscripts}"/functions
"${rscripts}"/cleanup
"${rscripts}"/setup


ln -sf ../sbin/susan_vadp_dumper-$TestName bin/susan_vadp_dumper_wrapper.sh
export PATH=${current_test_directory}/bin:$PATH
./reset_cbt.sh

# Directory to backup.
# This directory will be created by setup_data().
# BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
# setup_data

start_test

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
setdebug level=100 storage=File
label volume=TestVolume001 storage=File pool=Full
run job=$JobName level=Full yes
status director
status client
status storage=File
wait
messages



@#
@# now do an incremental
@#
run job=$JobName yes
wait
messages


@#
@# now do a restore
@#
@$out $tmp/log2.out
wait
restore client=susan-fd fileset=VMwareTest where=$tmp/susan-restores pluginoptions=python:localvmdk=yes select all done
yes
wait
messages
quit
END_OF_DATA

run_susan "$@"
check_for_zombie_jobs storage=File
stop_susan

check_two_logs

# Check restored disk image content
restored_disk_image=$(find $tmp/susan-restores -type f  -name "*.vmdk" | tail -1)
if file "$restored_disk_image" | grep "VMware4 disk image"; then
    echo "Restored disk image type OK"
else
    echo "Restored disk image ERROR: is not VMware disk image"
    dstat=1
fi

end_test
